﻿using System;
using System.Windows;
using TS3ServerManager.BL;

namespace TS3ServerManager.Windows
{
    /// <summary>
    /// Interaction logic for ServerModifyWindow.xaml
    /// </summary>
    public partial class ServerModifyWindow
    {
        #region Properties

        public string ServerName { get { return ServerModify.ServerName; } }
        public ServerConnectInfo ConnectInfo { get; protected set; }
        public bool IsEditMode { get; protected set; }

        #endregion

        #region Constructors

        public ServerModifyWindow()
        {
            InitializeComponent();
        }

		public void Init()
		{
			Init(null, null);
		}

        public void Init(string serverName, ServerConnectInfo connectInfo)
        {
            ConnectInfo = connectInfo;

            if ((serverName != null && connectInfo == null) || (serverName == null && connectInfo != null))
                throw new NotSupportedException("Invalid input combination");

            IsEditMode = serverName != null;
            ServerModify.Bind(serverName, connectInfo);
            Title = IsEditMode ? "Edit Server" : "Add Server";
            ModifyButton.Content = IsEditMode ? "edit" : "add";
        }

        #endregion

        private void ModifyButton_Click(object sender, RoutedEventArgs e)
        {
            ConnectInfo = ServerModify.ValidateUserInterface();

            if (ConnectInfo != null)
                DialogResult = true;
        }
    }
}